package com.lightdz.tshirtdz;

/**
 * Created by Administrator on 2018/12/27.
 */

        import org.springframework.context.annotation.Bean;
        import org.springframework.context.annotation.Configuration;
        import org.springframework.web.context.request.async.DeferredResult;
        import org.springframework.web.servlet.config.annotation.EnableWebMvc;

        import springfox.documentation.builders.ApiInfoBuilder;
        import springfox.documentation.builders.PathSelectors;
        import springfox.documentation.builders.RequestHandlerSelectors;
        import springfox.documentation.service.ApiInfo;
        import springfox.documentation.service.Contact;
        import springfox.documentation.spi.DocumentationType;
        import springfox.documentation.spring.web.plugins.Docket;
        import springfox.documentation.swagger2.annotations.EnableSwagger2;

//@Configuration //声明该类为配置类
//@EnableSwagger2 //声明启动Swagger2
//@EnableWebMvc //声明启动mvc
/**
 * 访问地址：http://localhost:9090/swagger-ui.html 目前swagger不可用404。
 */
public class SwaggerConfig{
    @Bean
    public Docket customDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                //.apis(RequestHandlerSelectors.basePackage("com.lightdz.tshirtdz.controller"))//扫描的包路径
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("DCC API接口")//文档说明
                .version("1.0.0")//文档版本说明
                .description("this is a description")
                .build();
    }

    //可以创建多个api docket
//    @Bean
//    public Docket demoApi() {
//        return new Docket(DocumentationType.SWAGGER_2)
//                .groupName("demo")
//                .genericModelSubstitutes(DeferredResult.class)
////              .genericModelSubstitutes(ResponseEntity.class)
//                .useDefaultResponseMessages(false)
//                .forCodeGeneration(false)
//                .pathMapping("/")
//                .select()
//                .paths(PathSelectors.any())
//                //.paths(or(regex("/demo/.*")))//过滤的接口
//                .build()
//                .apiInfo(testApiInfo());
//    }
    //构建 api文档的详细信息函数,注意这里的注解引用的是哪个
//    private ApiInfo testApiInfo() {
//        return new ApiInfoBuilder()
//                .title("Electronic Health Record(EHR) Platform API")//大标题
//                .description("EHR Platform's REST API, all the applications could access the Object model data via JSON.")//详细描述
//                .version("1.0")//版本
//                .termsOfServiceUrl("NO terms of service")
//                .contact(new Contact("小单", "http://blog.csdn.net/catoop", "365384722@qq.com"))//作者
//                .license("The Apache License, Version 2.0")
//                .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
//                .build();
//    }
}

